﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using rbac.Contracts.DTO.Input;
using rbac.Contracts.DTO.Output;
using rbac.Contracts.Interface;
using rbac.Domain.Entity;

namespace rbac.API.Controllers
{
    /// <summary>
    /// 角色管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RoleController : ControllerBase
    {
        IRoleService _service;
        ILogger<RoleController> _logger;

        public RoleController(IRoleService service, ILogger<RoleController> logger)
        {
            _service = service;
            _logger = logger;
        }
        /// <summary>
        /// 角色查询
        /// </summary>
        /// <param name="roleName"></param>
        /// <returns></returns>
        [HttpGet]
        [Authorize]
        public Results<List<RoleOutput>> SearchRoles(string? roleName)
        {
            return Results<List<RoleOutput>>.DataResult(_service.SearchRoles(roleName));
        }
        /// <summary>
        /// 角色添加
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        [HttpPost]
        public Results<int> Add([FromBody]RoleInput role)
        {
            return Results<int>.DataResult(_service.Add(role));


        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="idList"></param>
        /// <returns></returns>
        [HttpDelete]
        public Results<int> Delete([FromBody] List<int> idList)
        {

            return Results<int>.DataResult(_service.Delete(idList.ToArray()));
        }
        [HttpPut]
        public Results<int> Update([FromBody] RoleInput input)
        {
            return Results<int>.DataResult(_service.Update(input));
        }
    }
}
